﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;

using System.Text;
using System.Windows.Forms;
using QUANLYCHAMCONG.PL.CMS.Danhmuc;
using QUANLYCHAMCONG.PL.CMS;
using QUANLYCHAMCONG.BL.BUS;
using QUANLYCHAMCONG.PL.CMS.Maychamcong;
using QUANLYCHAMCONG.PL.CMS.Nhanvien;
using QUANLYCHAMCONG.PL.CMS.Hethong;
using QUANLYCHAMCONG.PL.CMS.BaoCao;
using QUANLYCHAMCONG.BL.Entities;
using QUANLYCHAMCONG.BL.Entities.Security;
using QUANLYCHAMCONG.BL.Entities.Import;
using QUANLYCHAMCONG.BL.BUS.Security;
using Hopthoai;
using QUANLYCHAMCONG.PL.CMS.Main;
namespace QUANLYCHAMCONG
{
    public partial class Form1 : Form
    {
        //danh muc
        Bangcap b;
        Chucvu cv;
        hopdong hd;
        Loaicongty lcty;
        Loaihopdong lhd;
        loaiphongban lpb;
        Nghenghiep nn;
        nghitangca ntc;
        phongban pb;
        thoigian tg;
        Thamsohethong ts;
        Loaihinh lh;
        Kyhieu kh;
        NgayPhep ngp;
        Ngayle nl;
        Ca ca;
        //may cham cong
        Loaimay lm;
        Tocdo td;
        Loaiketnoi kn;
        Khaibaomaychamcong chamcong;
        Upnhanvientoimaychamcong nhanvienmaychamcong;
        DownloadNhanVien downloadnhanvien;
        Docdulieutufile docfile;
        DownLoad_vantay vantay;
        //danh sach nhan vien
        Nhanvien nv;
        DangkyTangCa tangca;
        Dangkyditre tre;
        DangKyVeSom som;
        DangkyNghiPhep phep;
        Dangkydicongtac congtac;
        LichLamviec lich;
        ImportNhanvienFromFile themnhanvientufile;
        //he thong 
        Congty cty;
        frmcauhinhketnoi cauhinh;
        frmbackup back;
        //phan quyen
        QUANLYCHAMCONG.PL.CMS.Hethong.Menu mnu;
        Group group;
        Users user;
        Phanquyen phanquyen;
        Taidulieutheongay taidulieu;
        //bao cao 
        baocaotheogionguon gionguon;
        Baocaogiochialamhai checkinout;
        Chitietchamcong chitiet;
        Tongcong tongcong;
        public Form1()
        {
            InitializeComponent();
        }
        
        public void AddNgayLe(ref GroupBox grcontent)
        {
            nl = new Ngayle();
            nl.Close += new Ngayle._Close(AddHome);
            nl.Dock = DockStyle.Top;
            grcontent.Controls.Add(nl);
        }
        public void AddNgayPhep(ref GroupBox grcontent)
        {
            ngp = new NgayPhep();
            ngp.Close += new NgayPhep._Close(AddHome);
            ngp.Dock = DockStyle.Top;
            grcontent.Controls.Add(ngp);
        }
        public void AddKyHieu(ref GroupBox grcontent)
        {
            kh = new Kyhieu();
            kh.Close += new Kyhieu._Close(AddHome);
            kh.Dock = DockStyle.Top;
            grcontent.Controls.Add(kh);
        }
        public void AddLoaiHinh(ref GroupBox grcontent)
        {
            lh = new Loaihinh();
            lh.Close += new Loaihinh._Close(AddHome);
            lh.Dock = DockStyle.Top;
            grcontent.Controls.Add(lh);
        }
        public void AddThamSoHeThong(ref GroupBox grcontent)
        {
            ts = new Thamsohethong();
            ts.Close += new Thamsohethong._Close(AddHome);
            ts.Dock = DockStyle.Top;
            grcontent.Controls.Add(ts);
        }
        public void AddThoiGian(ref GroupBox grcontent)
        {
            tg = new thoigian();
            tg.Close += new thoigian._Close(AddHome);
            tg.Dock = DockStyle.Top;
            grcontent.Controls.Add(tg);
        }
        public void AddPhongBan(ref GroupBox grcontent)
        {
            pb = new phongban();
            pb.Close += new phongban._Close(AddHome);
            pb.AddLoaiPB += new phongban._AddLoaiPB(pb_AddLoaiPB);
            pb.Dock = DockStyle.Top;
            pb.UcStatusRoom = this.total1;
            grcontent.Controls.Add(pb);
        }
        void pb_AddLoaiPB()
        {
            AddLoaiPhongBan(ref this.grcontent);
        }
        public void AddNghiTangCa(ref GroupBox grcontent)
        {
            ntc = new nghitangca();
            ntc.Close += new nghitangca._Close(AddHome);
            ntc.AddLoaiTG += new nghitangca._AddLoaiTG(ntc_AddLoaiTG);
            ntc.Dock = DockStyle.Top;
            grcontent.Controls.Add(ntc);
        }
        void ntc_AddLoaiTG()
        {
            AddThoiGian(ref this.grcontent);
        }
        public void AddNgheNghiep(ref GroupBox grcontent)
        {
            nn = new Nghenghiep();
            nn.Close += new Nghenghiep._Close(AddHome);
            nn.Dock = DockStyle.Top;
            grcontent.Controls.Add(nn);
        }
        public void AddLoaiPhongBan(ref GroupBox grcontent)
        {
            lpb = new loaiphongban();
            lpb.Close += new loaiphongban._Close(AddHome);
            lpb.Dock = DockStyle.Top;
            grcontent.Controls.Add(lpb);
        }
        public void AddHopDong(ref GroupBox grcontent)
        {
            hd = new hopdong();
            hd.Close += new hopdong._Close(AddHome);
            hd.Dock = DockStyle.Top;
            grcontent.Controls.Add(hd);
        }
        public void AddChucvu(ref GroupBox grcontent)
        {
            cv = new Chucvu();
            cv.Close += new Chucvu._Close(AddHome);
            cv.Dock = DockStyle.Top;
            grcontent.Controls.Add(cv);
        }
        public void AddBangCap(ref GroupBox grcontent)
        {
            b = new Bangcap();
            b.Close += new Bangcap._Close(AddHome);
            b.Dock = DockStyle.Top;
            grcontent.Controls.Add(b);
        }
        public void AddLoaiCongty(ref GroupBox grcontent)
        {
            lcty = new Loaicongty();
            lcty.Close += new Loaicongty._Close(AddHome);
            lcty.Dock = DockStyle.Top;
            grcontent.Controls.Add(lcty);
        }
        public void AddLoaiHopDong(ref GroupBox grcontent)
        {
            lhd = new Loaihopdong();
            lhd.Close += new Loaihopdong._Close(AddHome);
            lhd.Dock = DockStyle.Top;
            grcontent.Controls.Add(lhd);
        }
        public void AddLoaiMay(ref GroupBox grcontent)
        {
            lm = new Loaimay();
            lm.Close += new Loaimay._Close(AddHome);
            lm.Dock = DockStyle.Top;
            grcontent.Controls.Add(lm);

        }
        public void AddTocDO(ref GroupBox grcontent)
        {
            td = new Tocdo();
            td.Close += new Tocdo._Close(AddHome);
            td.Dock = DockStyle.Top;
            grcontent.Controls.Add(td);
        }
        public void AddKetNoi(ref GroupBox gr)
        {
            kn = new Loaiketnoi();
            kn.Close += new Loaiketnoi._Close(AddHome);
            kn.Dock = DockStyle.Top;
            gr.Controls.Add(kn);
        }
        public void AddCa(ref GroupBox gr)
        {
            ca = new Ca();
            ca.Close += new Ca._Close(AddHome);
            ca.Dock = DockStyle.Top;
            gr.Controls.Add(ca);
        }
        public void AddDsNhanVien(ref GroupBox gr)
        {
            try
            {
                nv = new Nhanvien();
                nv.Close += new Nhanvien._Close(AddHome);
                nv.Dock = DockStyle.Top;
                nv.UcStatusRoom = this.total1;
                gr.Controls.Add(nv);
            }
            catch
            {
                MessageBox.Show("Máy chưa cài office !");
                return;
            }
        }
        public void AddThongTinCongTy(ref GroupBox gr)
        {
            cty = new Congty();
            cty.Close += new Congty._Close(AddHome);
            cty.Dock = DockStyle.Top;
            gr.Controls.Add(cty);
        }
        public void AddTangCa(ref GroupBox gr)
        {
            tangca = new DangkyTangCa();
            tangca.Close += new DangkyTangCa._Close(AddHome);
            tangca.Dock = DockStyle.Top;
            this.tangca.LoaiLink = "Đăng ký tăng ca";
            this.tangca.Flag = 0;
            gr.Controls.Add(tangca);
        }
        public void AddTangcaDitre(ref GroupBox gr)
        {
            tre = new Dangkyditre();
            tre.Close += new Dangkyditre._Close(AddHome);
            tre.Dock = DockStyle.Top;
            this.tre.Flag = 1;
            this.tre.LoaiLink = "Đăng ký Đi trễ";
            gr.Controls.Add(tre);
        }
        public void AddTangcaVeSom(ref GroupBox gr)
        {
            som = new DangKyVeSom();
            som.Close += new DangKyVeSom._Close(AddHome);
            som.Dock = DockStyle.Top;
            this.som.Flag = 2;
            this.som.LoaiLink = "Đăng ký về sớm";
            gr.Controls.Add(som);
        }
        public void AddTangCaNghiphep(ref GroupBox gr)
        {
            phep = new DangkyNghiPhep();
            phep.Dock = DockStyle.Top;
            phep.Close += new DangkyNghiPhep._Close(AddHome);
            this.phep.Flag = 3;
            this.phep.LoaiLink = "Đăng ký nghỉ phép";
            gr.Controls.Add(phep);
        }
        public void AddTangCaDicongtac(ref GroupBox gr)
        {
            congtac = new  Dangkydicongtac();
            congtac.Dock = DockStyle.Top;
            congtac.Close += new Dangkydicongtac._Close(AddHome);
            this.congtac.Flag = 4;
            this.congtac.LoaiLink = "Đăng ký Đi công tác";
            congtac.UcLoad = this.total1;
            gr.Controls.Add(congtac);
        }
        void AddMayChamCong(ref GroupBox gr)
        {
            chamcong = new Khaibaomaychamcong();
            chamcong.Close += new Khaibaomaychamcong._Close(AddHome);
            chamcong.Dock = DockStyle.Top;
            gr.Controls.Add(chamcong);
        }
        void AddLichLamViec(ref GroupBox gr)
        {
            lich = new LichLamviec();
            lich.Close += new LichLamviec._Close(AddHome);
            lich.Dock = DockStyle.Top;
            gr.Controls.Add(lich);
        }
        //phan  he thong
        void AddMenu(ref GroupBox gr)
        {
            mnu = new QUANLYCHAMCONG.PL.CMS.Hethong.Menu();
            mnu.Close += new QUANLYCHAMCONG.PL.CMS.Hethong.Menu._Close(AddHome);
            mnu.Dock = DockStyle.Top;
            gr.Controls.Add(mnu);
        }
        void AddGroup(ref GroupBox gr)
        {
            group = new Group();
            group.Close += new Group._Close(AddHome);
            group.Dock = DockStyle.Top;
            gr.Controls.Add(group);
        }
        void AddUSers(ref GroupBox gr)
        {
            user = new Users();
            user.Close += new Users._Close(AddHome);
            user.Dock = DockStyle.Top;
            gr.Controls.Add(user);
        }
        void AddPhanquyen(ref GroupBox gr)
        {
            phanquyen = new Phanquyen();
            phanquyen.Close += new Phanquyen._Close(AddHome);
            phanquyen.Dock = DockStyle.Top;
            gr.Controls.Add(phanquyen);
        }
        void AddNhanVienTuFile(ref GroupBox gr)
        {
            themnhanvientufile = new ImportNhanvienFromFile();
            themnhanvientufile.Close += new ImportNhanvienFromFile._Close(AddHome);
            themnhanvientufile.Dock = DockStyle.Top;
            themnhanvientufile.UcLoad = this.total1;
            gr.Controls.Add(themnhanvientufile);
        }
        void AddTaiDulieu(ref GroupBox gr)
        {
            taidulieu = new Taidulieutheongay();
            taidulieu.Close += new Taidulieutheongay._Close(AddHome);
            taidulieu.Dock = DockStyle.Top;
            taidulieu.UcStatusRoom = this.total1;
            gr.Controls.Add(taidulieu);
        }
        void AddNhanvienMayChamCong(ref GroupBox gr)
        {
            nhanvienmaychamcong = new Upnhanvientoimaychamcong();
            nhanvienmaychamcong.Close += new Upnhanvientoimaychamcong._Close(AddHome);
            nhanvienmaychamcong.UcStatusRoom = this.total1;
            nhanvienmaychamcong.Dock = DockStyle.Top;
            gr.Controls.Add(nhanvienmaychamcong);
        }
        void AddDownloadNhanvien(ref GroupBox gr)
        {
            downloadnhanvien = new DownloadNhanVien();
            downloadnhanvien.Close += new DownloadNhanVien._Close(AddHome);
            downloadnhanvien.Dock = DockStyle.Top;
            downloadnhanvien.UcStatusRoom = this.total1;
            gr.Controls.Add(downloadnhanvien);
        }
        void AddDownloadVantay(ref GroupBox gr)
        {
            vantay = new DownLoad_vantay();
            vantay.Close += new DownLoad_vantay._Close(AddHome);
            vantay.Dock = DockStyle.Top;
            vantay.UcStatusRoom = this.total1;
            gr.Controls.Add(vantay);
        }
        void AddBaoCaoGioNguon(ref GroupBox gr)
        {
            gionguon = new baocaotheogionguon();
            gionguon.Close += new baocaotheogionguon._Close(AddHome);
            gionguon.Dock = DockStyle.Top;
            gr.Controls.Add(gionguon);
        }
        void AddBaoCaoINOUT(ref GroupBox gr)
        {
            checkinout = new Baocaogiochialamhai();
            checkinout.Close += new Baocaogiochialamhai._Close(AddHome);
            checkinout.Dock = DockStyle.Top;
            gr.Controls.Add(checkinout);
        }
        void AddDuLieuTuFile(ref GroupBox gr)
        {
            docfile = new Docdulieutufile();
            docfile.Close += new Docdulieutufile._Close(AddHome);
            docfile.UcStatusRoom = this.total1;
            docfile.Dock = DockStyle.Top;
            gr.Controls.Add(docfile);
        }
        void AddChamcongChitiet(ref GroupBox gr)
        {
            chitiet = new Chitietchamcong();
            chitiet.Close += new Chitietchamcong._Close(AddHome);
            chitiet.Dock = DockStyle.Top;
            gr.Controls.Add(chitiet);
        }
        void AddThongke(ref GroupBox gr)
        {
            tongcong = new Tongcong();
            tongcong.Close += new Tongcong._Close(AddHome);
            tongcong.Dock = DockStyle.Top;
            gr.Controls.Add(tongcong);
        }
        #region "Event Content"
        private void EventOFContent()
        {
            this.ctmain.DanhsachNhanvien += new Content._DanhsachClick(mlmain_DsNhanVien);
            this.ctmain.Lichsunhanvien += new Content._Lichsunhanvien(mlmain_ThemNhanvienTuFile);
            this.ctmain.Chamcongnhanvien += new Content._Chamcongnhanvien(mlmain_DangkyVeSom);
            this.ctmain.Hopdongnhanvien += new Content._Hopdongnhanvien(mlmain_HopDong);
            this.ctmain.Taotaikhoan += new Content._Taotaikhoan(mlmain_User);
            this.ctmain.PhanquyenTaikhoan += new Content._PhanquyenTaikhoan(mlmain_PhanQuyen);
            this.ctmain.Cauhinhhethong += new Content._Cauhinhhethong(ctmain_Cauhinhhethong);
            this.ctmain.Thaydoipass += new Content._Thaydoipass(thanhcongcu_ChangePass);
            this.ctmain.BackupDulieu += new Content._BackupDulieu(mlmain_Backup);
            this.ctmain.Dangkymaychamcong += new Content._Dangkymaychamcong(mlmain_MayChamCong);
            this.ctmain.Ketnoimaychamcong += new Content._Ketnoimaychamcong(mlmain_TaiDuLieu);
            this.ctmain.Saoluudulieumaychamcong += new Content._Saoluudulieumaychamcong(mlmain_DownloadVantay);
            this.ctmain.DownloadNhanvien += new Content._DownloadNhanvien(mlmain_DownloadNhanvien);
            this.ctmain.Thamsohethong += new Content._Thamsohethong(mlmain_Thamso);
            this.ctmain.Ngayle += new Content._Ngayle(mlmain_NgayLe);
            this.ctmain.Ca += new Content._Ca(mlmain_Ca);
            this.ctmain.Congty += new Content._Congty(mlmain_ThongTinCongTy);
            this.ctmain.Ngaylamviec += new Content._Ngaylamviec(mlmain_LichLamViec);
            this.ctmain.Dangkytangca += new Content._Dangkytangca(mlmain_DangkyCa);
            this.ctmain.Dangkyditrevesom += new Content._Dangkyditrevesom(mlmain_Dangkydisomvetre);
            this.ctmain.Dangkynghiphep += new Content._Dangkynghiphep(mlmain_Dangkynghiphep);
            this.ctmain.Dangkydicongtac += new Content._Dangkydicongtac(mlmain_DangkyCongtac);
            this.ctmain.Baocaotinhhinhlamviec += new Content._Baocaotinhhinhlamviec(mlmain_Thongke);
            this.ctmain.Chamcongchitiet += new Content._Chamcongchitiet(mlmain_Chamcongchitiet);
            this.ctmain.Danhsachnhanvienvang += new Content._Danhsachnhanvienvang(mlmain_Chamcongchitiet);
            this.ctmain.Thongke += new Content._Thongke(mlmain_Thongke);
            //event for all close
           
        }

        void ctmain_Cauhinhhethong()
        {
            frmHoidap f = new frmHoidap("Bạn không thể cấu hình hệ thống khi đang trong chương trình vui lòng đăng xuất để cấu hình!", frmHoidap.CO.an, frmHoidap.KHONG.an, frmHoidap.THOAT.an, frmHoidap.HINH.baoloi);
            f.ShowDialog();
        }
        void Thongke()
        {
 	       
        }
        #endregion
        #region "Event Quicktool"
        private void EventOfQuickTool()
        {
            this.thanhcongcu.Home += new QuickBar._Home(Home);
            this.thanhcongcu.PhanQuyen += new QuickBar._PhanQuyen(mlmain_PhanQuyen);
            this.thanhcongcu.Nhanvien += new QuickBar._Nhanvien(mlmain_DsNhanVien);
            this.thanhcongcu.ChamCong += new QuickBar._Chamcong(mlmain_Chamcongchitiet);
            this.thanhcongcu.TangCa += new QuickBar._TangCa(mlmain_DangkyCa);
            this.thanhcongcu.DangKyMay += new QuickBar._DangKyMay(mlmain_MayChamCong);
            this.thanhcongcu.KetNoiMayChamCong += new QuickBar._KetNoiMayChamCong(mlmain_DownloadNhanvien);
            this.thanhcongcu.DanhMuc += new QuickBar._DanhMuc(mlmain_Ca);
            this.thanhcongcu.BaoCao += new QuickBar._BaoCao(mlmain_Thongke);
            this.thanhcongcu.PhanQuyen += new QuickBar._PhanQuyen(mlmain_PhanQuyen);
            this.thanhcongcu.ChangePass += new QuickBar._ChangePass(thanhcongcu_ChangePass);
            this.thanhcongcu.Database += new QuickBar._Database(mlmain_Backup);
        }
        void thanhcongcu_ChangePass()
        {
            Changepass chang = new Changepass();
            chang.ShowIcon = false;
            chang.ShowInTaskbar = false;
            chang.ShowDialog();
        }
        void thanhcongcu_PhanQuyen()
        {
            throw new NotImplementedException();
        }
        void Home()
        {
            Common.Remove(ref this.grcontent);
            AddHome();
        }
        #endregion
        #region "Event MenuLeft"
        private void EventMenu()
        {
            //danh muc
            this.mlmain.Bangcap += new MenuLeft._Bangcap(mlmain_Bangctyp);
            this.mlmain.Chucvu += new MenuLeft._Chucvu(mlmain_Chucvu);
            this.mlmain.HopDong += new MenuLeft._HopDong(mlmain_HopDong);
            this.mlmain.LoaiCongty += new MenuLeft._LoaiCongty(mlmain_LoaiCongty);
            this.mlmain.LoaiHopDong += new MenuLeft._LoaiHopDong(mlmain_LoaiHopDong);
            this.mlmain.LoaiPhongBan += new MenuLeft._LoaiPhongBan(mlmain_LoaiPhongBan);
            this.mlmain.Nghenghiep += new MenuLeft._Nghenghiep(mlmain_Nghenghiep);
            this.mlmain.GioNgiTangCa += new MenuLeft._GioNgiTangCa(mlmain_GioNgiTangCa);
            this.mlmain.Phongban += new MenuLeft._Phongban(mlmain_Phongban);
            this.mlmain.Loaithoigian += new MenuLeft._Loaithoigian(mlmain_Loaithoigian);
            this.mlmain.Thamso += new MenuLeft._Thamso(mlmain_Thamso);
            this.mlmain.LoaiHinh += new MenuLeft._LoaiHinh(mlmain_LoaiHinh);
            this.mlmain.Kyhieu += new MenuLeft._Kyhieu(mlmain_Kyhieu);
            this.mlmain.NgayPhep += new MenuLeft._NgayPhep(mlmain_NgayPhep);
            this.mlmain.NgayLe += new MenuLeft._NgayLe(mlmain_NgayLe);
            this.mlmain.Ca += new MenuLeft._Ca(mlmain_Ca);
            //loai may cham cong
            this.mlmain.LoaiMay += new MenuLeft._LoaiMay(mlmain_LoaiMay);
            this.mlmain.TocDo += new MenuLeft._TocDo(mlmain_TocDo);
            this.mlmain.KetNoi += new MenuLeft._KetNoi(mlmain_KetNoi);
            this.mlmain.MayChamCong += new MenuLeft._MayChamCong(mlmain_MayChamCong);
            this.mlmain.TaiDuLieu += new MenuLeft._EventMaychamcong(mlmain_TaiDuLieu);
            this.mlmain.NhanvienMayChamcong += new MenuLeft._EventMaychamcong(mlmain_NhanvienMayChamcong);
            this.mlmain.DownloadNhanvien += new MenuLeft._EventMaychamcong(mlmain_DownloadNhanvien);
            this.mlmain.DownloadVantay += new MenuLeft._EventMaychamcong(mlmain_DownloadVantay);
            this.mlmain.Laydulieutufile += new MenuLeft._EventMaychamcong(mlmain_Laydulieutufile);
            //danh sach nhan vien
            this.mlmain.DsNhanVien += new MenuLeft._DsNhanVien(mlmain_DsNhanVien);
            this.mlmain.DangkyCa += new MenuLeft._DangkyCa(mlmain_DangkyCa);
            this.mlmain.DangkyCongtac += new MenuLeft._DangkyCongtac(mlmain_DangkyCongtac);
            this.mlmain.Dangkydisomvetre += new MenuLeft._Dangkydisomvetre(mlmain_Dangkydisomvetre);
            this.mlmain.Dangkynghiphep += new MenuLeft._Dangkynghiphep(mlmain_Dangkynghiphep);
            this.mlmain.DangkyVeSom += new MenuLeft._DangkyVeSom(mlmain_DangkyVeSom);
            this.mlmain.LichLamViec += new MenuLeft._LichLamViec(mlmain_LichLamViec);
            this.mlmain.ThemNhanvienTuFile += new MenuLeft._QuanTri(mlmain_ThemNhanvienTuFile);
            //thong tin he thong 
            this.mlmain.ThongTinCongTy += new MenuLeft._ThongTinCongTy(mlmain_ThongTinCongTy);
            this.mlmain.CauHinhHeThong += new MenuLeft._CauHinhHeThong(mlmain_CauHinhHeThong);
            this.mlmain.Backup += new MenuLeft._Backup(mlmain_Backup);
            this.mlmain.Retore += new MenuLeft._Retore(mlmain_Retore);
            this.mlmain.Logout += new MenuLeft._Logout(mlmain_Logout);
            this.mlmain.Thoat += new MenuLeft._Thoat(mlmain_Thoat);
            this.mlmain.ChangePass += new MenuLeft._ChangePass(thanhcongcu_ChangePass);
            //quan tri he thong 
            this.mlmain.Menu += new MenuLeft._QuanTri(mlmain_Menu);
            this.mlmain.Group += new MenuLeft._QuanTri(mlmain_Group);
            this.mlmain.User += new MenuLeft._QuanTri(mlmain_User);
            this.mlmain.PhanQuyen += new MenuLeft._QuanTri(mlmain_PhanQuyen);
            this.mlmain.dangkybanquyen += new MenuLeft._ActiveLinece(mlmain_dangkybanquyen);
            //bao cao 
            this.mlmain.TimeOrigin += new MenuLeft._EventReport(mlmain_TimeOrigin);
            this.mlmain.CheckInOut += new MenuLeft._EventReport(mlmain_CheckInOut);
            this.mlmain.Chamcongchitiet += new MenuLeft._EventReport(mlmain_Chamcongchitiet);
            this.mlmain.Thongke += new MenuLeft._EventReport(mlmain_Thongke);
        }

        void mlmain_dangkybanquyen()
        {
            Frmdangkymaychamcong f = new Frmdangkymaychamcong();
            f.ShowDialog();
        }
        public void ReloadStattus()
        {
            try
            {
                Thongke tk = new Thongke();
                this.total1.DtData = BAOCAOBUS.ThongkeTotal(tk);
                this.total1.Settext();
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
        void mlmain_Thongke()
        {
            Common.Remove(ref this.grcontent);
            AddThongke(ref this.grcontent);
        }
        void mlmain_Chamcongchitiet()
        {
            Common.Remove(ref this.grcontent);
            AddChamcongChitiet(ref this.grcontent);
        }
        void mlmain_Laydulieutufile()
        {
            Common.Remove(ref this.grcontent);
            AddDuLieuTuFile(ref this.grcontent);
        }
        void mlmain_Thoat()
        {
            Application.Exit();

        }
        void mlmain_CheckInOut()
        {
            Common.Remove(ref this.grcontent);
            AddBaoCaoINOUT(ref this.grcontent);
        }
        void mlmain_TimeOrigin()
        {
            Common.Remove(ref this.grcontent);
            AddBaoCaoGioNguon(ref this.grcontent);
        }
        void mlmain_DownloadVantay()
        {
            Common.Remove(ref this.grcontent);
            AddDownloadVantay(ref this.grcontent);
        }
        void mlmain_DownloadNhanvien()
        {
            Common.Remove(ref this.grcontent);
            AddDownloadNhanvien(ref this.grcontent);
        }
        void mlmain_NhanvienMayChamcong()
        {
             Common.Remove(ref this.grcontent);
             AddNhanvienMayChamCong(ref this.grcontent);
        }
        void mlmain_TaiDuLieu()
        {
            Common.Remove(ref this.grcontent);
            AddTaiDulieu(ref this.grcontent);
            
        }
        void mlmain_ThemNhanvienTuFile()
        {
            Common.Remove(ref this.grcontent);
            AddNhanVienTuFile(ref this.grcontent);
        }
        void mlmain_PhanQuyen()
        {
            Common.Remove(ref this.grcontent);
            AddPhanquyen(ref this.grcontent);
        }
        void mlmain_User()
        {
            Common.Remove(ref this.grcontent);
            AddUSers(ref this.grcontent);
        }
        void mlmain_Group()
        {
            Common.Remove(ref this.grcontent);
            AddGroup(ref this.grcontent);
        }
        void mlmain_Menu()
        {
            Common.Remove(ref this.grcontent);
            AddMenu(ref this.grcontent);
        }
        void mlmain_Logout()
        {
            frmLogin f = new frmLogin();
            f.Show();
            this.Hide();
        }
        void mlmain_LichLamViec()
        {
            Common.Remove(ref this.grcontent);
            AddLichLamViec(ref this.grcontent);
        }
        void mlmain_MayChamCong()
        {
            Common.Remove(ref this.grcontent);
            AddMayChamCong(ref this.grcontent);
        }
        void mlmain_Retore()
        {
            back = new frmbackup();
            back.Tenform = "Phục hồi dữ liệu";
            back.Flag = 2;
            back.Text = "Phục hồi dữ liệu";
            back.ShowDialog();
        }
        void mlmain_Backup()
        {
            back = new frmbackup();
            back.Tenform = "Sao lưu dữ liệu";
            back.Text = "Sao lưu dữ liệu";
            back.Flag = 1;
            back.ShowDialog();
        }
        void mlmain_CauHinhHeThong()
        {
            cauhinh = new frmcauhinhketnoi();
            cauhinh.ShowDialog();
        }
        void mlmain_DangkyVeSom()
        {
            Common.Remove(ref this.grcontent);
            AddTangcaVeSom(ref this.grcontent);
        }
        void mlmain_Dangkynghiphep()
        {
           
            Common.Remove(ref this.grcontent);
            AddTangCaNghiphep(ref this.grcontent);
        }
        void mlmain_Dangkydisomvetre()
        {
           
            Common.Remove(ref this.grcontent);
            AddTangcaDitre(ref this.grcontent);
        }
        void mlmain_DangkyCongtac()
        {
           
            Common.Remove(ref this.grcontent);
            
            AddTangCaDicongtac(ref this.grcontent);
        }
        void mlmain_DangkyCa()
        {
           
            Common.Remove(ref this.grcontent);
            AddTangCa(ref this.grcontent);
        }
        void mlmain_ThongTinCongTy()
        {
            Common.Remove(ref this.grcontent);
            AddThongTinCongTy(ref this.grcontent);
        }
        void mlmain_DsNhanVien()
        {
            Common.Remove(ref this.grcontent);
            AddDsNhanVien(ref this.grcontent);
        }
        void mlmain_Ca()
        {
            Common.Remove(ref this.grcontent);
            AddCa(ref this.grcontent);
        }
        void mlmain_KetNoi()
        {
            Common.Remove(ref this.grcontent);
            AddKetNoi(ref this.grcontent);
        }
        void mlmain_TocDo()
        {
            Common.Remove(ref this.grcontent);
            AddTocDO(ref this.grcontent);
        }
        void mlmain_LoaiMay()
        {
            Common.Remove(ref this.grcontent);
            AddLoaiMay(ref this.grcontent);
        }
        void mlmain_NgayLe()
        {
            Common.Remove(ref this.grcontent);
            AddNgayLe(ref this.grcontent);
        }
        void mlmain_NgayPhep()
        {
            Common.Remove(ref this.grcontent);
           AddNgayPhep(ref this.grcontent);
        }
        void mlmain_Kyhieu()
        {

            Common.Remove(ref this.grcontent);
            AddKyHieu(ref this.grcontent);
        }
        void mlmain_LoaiHinh()
        {
            Common.Remove(ref this.grcontent);
            AddLoaiHinh(ref this.grcontent);
        }
        void mlmain_Thamso()
        {
            Common.Remove(ref this.grcontent);
            AddThamSoHeThong(ref this.grcontent);
        }
        void mlmain_Loaithoigian()
        {
            Common.Remove(ref this.grcontent);
            AddThoiGian(ref this.grcontent);
        }
        void mlmain_Phongban()
        {
            Common.Remove(ref this.grcontent);
            AddPhongBan(ref this.grcontent);
        }
        void mlmain_GioNgiTangCa()
        {
            Common.Remove(ref this.grcontent);
            AddNghiTangCa(ref this.grcontent);
        }
        void mlmain_Nghenghiep()
        {
            Common.Remove(ref this.grcontent);
            AddNgheNghiep(ref this.grcontent);
        }
        void mlmain_LoaiPhongBan()
        {
            Common.Remove(ref this.grcontent);
            AddLoaiPhongBan(ref this.grcontent);
        }
        void mlmain_LoaiHopDong()
        {
            Common.Remove(ref this.grcontent);
            AddLoaiHopDong(ref this.grcontent);
        }
        void mlmain_LoaiCongty()
        {
            Common.Remove(ref this.grcontent);
            AddLoaiCongty(ref this.grcontent);
        }
        void mlmain_HopDong()
        {
            Common.Remove(ref this.grcontent);
            AddHopDong(ref this.grcontent);
        }
        void mlmain_Chucvu()
        {
            Common.Remove(ref this.grcontent);
            AddChucvu(ref this.grcontent);
        }
        void mlmain_Bangctyp()
        {
            Common.Remove(ref this.grcontent);
            AddBangCap(ref this.grcontent);
        }
        #endregion
        #region "Add-Remove Control"
        private void AddHome()
        {
            Content c = new Content();
            c.DanhsachNhanvien += new Content._DanhsachClick(mlmain_DsNhanVien);
            c.Lichsunhanvien += new Content._Lichsunhanvien(mlmain_ThemNhanvienTuFile);
            c.Chamcongnhanvien += new Content._Chamcongnhanvien(mlmain_DangkyVeSom);
            c.Hopdongnhanvien += new Content._Hopdongnhanvien(mlmain_HopDong);
            c.Taotaikhoan += new Content._Taotaikhoan(mlmain_User);
            c.PhanquyenTaikhoan += new Content._PhanquyenTaikhoan(mlmain_PhanQuyen);
            c.Cauhinhhethong += new Content._Cauhinhhethong(ctmain_Cauhinhhethong);
            c.Thaydoipass += new Content._Thaydoipass(thanhcongcu_ChangePass);
            c.BackupDulieu += new Content._BackupDulieu(mlmain_Backup);
            c.Dangkymaychamcong += new Content._Dangkymaychamcong(mlmain_MayChamCong);
            c.Ketnoimaychamcong += new Content._Ketnoimaychamcong(mlmain_TaiDuLieu);
            c.Saoluudulieumaychamcong += new Content._Saoluudulieumaychamcong(mlmain_DownloadVantay);
            c.DownloadNhanvien += new Content._DownloadNhanvien(mlmain_DownloadNhanvien);
            c.Thamsohethong += new Content._Thamsohethong(mlmain_Thamso);
            c.Ngayle += new Content._Ngayle(mlmain_NgayLe);
            c.Ca += new Content._Ca(mlmain_Ca);
            c.Congty += new Content._Congty(mlmain_ThongTinCongTy);
            c.Ngaylamviec += new Content._Ngaylamviec(mlmain_LichLamViec);
            c.Dangkytangca += new Content._Dangkytangca(mlmain_DangkyCa);
            c.Dangkyditrevesom += new Content._Dangkyditrevesom(mlmain_Dangkydisomvetre);
            c.Dangkynghiphep += new Content._Dangkynghiphep(mlmain_Dangkynghiphep);
            c.Dangkydicongtac += new Content._Dangkydicongtac(mlmain_DangkyCongtac);
            c.Baocaotinhhinhlamviec += new Content._Baocaotinhhinhlamviec(mlmain_Thongke);
            c.Chamcongchitiet += new Content._Chamcongchitiet(mlmain_Chamcongchitiet);
            c.Danhsachnhanvienvang += new Content._Danhsachnhanvienvang(mlmain_Chamcongchitiet);
            c.Thongke += new Content._Thongke(mlmain_Thongke);
            Point p = new Point(3, 8);
            c.Dock = DockStyle.Top;
            this.grcontent.Controls.Add(c);
            Reauthen(c);
        }
        void Reauthen(Content c)
        {
            Authencation au = new Authencation();
            au.USERNAME = Session.UserName;
            DataTable dt = new DataTable();
            dt = MENUGROUPBUS.AuthencationValues(au);
            if (dt.Rows.Count != 0)// la nhan vien nay da duoc phan quyen 
            {
                c.Dataactive = dt;
                 c.SetEnableLink();
            }
            else
            {
                frmHoidap f = new frmHoidap("Tên Đăng nhập này chưa được phân quyền !", frmHoidap.CO.an, frmHoidap.KHONG.an, frmHoidap.THOAT.an, frmHoidap.HINH.baoloi);
                f.ShowDialog();
            }
        }
        #endregion
        private void Form1_Load(object sender, EventArgs e)
        {
            EventOFContent();
            EventOfQuickTool();
            EventMenu();
            ReloadStattus();
            CheckAuthencation();
        }
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }
        void CheckAuthencation()
        { 
            //lay toan bo danh sach ma user do duoc phep truy suat
            Authencation au = new Authencation();
            au.USERNAME = Session.UserName;
            DataTable dt = new DataTable();
            dt = MENUGROUPBUS.AuthencationValues(au);
            if (dt.Rows.Count != 0)// la nhan vien nay da duoc phan quyen 
            {
                this.mlmain.Authen = dt;
                this.mlmain.Active();
                this.thanhcongcu.Dt = dt;
                this.thanhcongcu.Authen();
                this.ctmain.Dataactive = dt;
                this.ctmain.SetEnableLink();
            }
            else
            {
                frmHoidap f = new frmHoidap("Tên Đăng nhập này chưa được phân quyền !", frmHoidap.CO.an, frmHoidap.KHONG.an, frmHoidap.THOAT.an, frmHoidap.HINH.baoloi);
                f.ShowDialog();
            }

        }

        private void header1_Click(object sender, EventArgs e)
        {
            try
            {
                System.Diagnostics.Process.Start("mailto:hangocthanh3107@gmail.com");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
           
        }

    }
}
